//package com.koron.css2.meterService.impl;
//
//import com.koron.css2.ServerInterface;
//import com.koron.css2.baseConfig.mapper.BaseReceiptAccessoryMapper;
//import com.koron.css2.meterService.bean.MsChangeHistoryBean;
//import com.koron.css2.meterService.bean.MsChgPlanBean;
//import com.koron.css2.meterService.bean.MsChgPlanDetailBean;
//import com.koron.css2.meterService.bean.query.MsChangeHistoryQuery;
//import com.koron.css2.meterService.dto.MsChgPlanDetailDto;
//import com.koron.css2.meterService.dto.MsInfoDto;
//import com.koron.css2.meterService.mapper.MsChangeHistoryMapper;
//import com.koron.css2.meterService.mapper.MsChgPlanDetailMapper;
//import com.koron.css2.meterService.mapper.MsChgPlanMapper;
//import com.koron.css2.serviceManage.bean.RequestBean;
//import com.koron.css2.serviceManage.bean.ServicePtUserBean;
//import com.koron.css2.serviceManage.bean.UserInfoBean;
//import com.koron.css2.serviceManage.utils.JsonUtils;
//import com.koron.util.Constant;
//import com.koron.util.Tools;
//import org.apache.commons.collections4.CollectionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.koron.ebs.mybatis.SessionFactory;
//import org.swan.bean.MessageBean;
//
//import java.util.*;
//
///**
// *
// * 表计变更历史添加
// * */
//public class MsChaHistoryAdd implements ServerInterface {
//    @Override
//    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
//        MessageBean<Integer> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "添加成功", Integer.class);
//        try {
//
//
//            MsChangeHistoryMapper mapper = factory.getMapper(MsChangeHistoryMapper.class);
//            MsChangeHistoryQuery msChangeHistoryQuery = JsonUtils.objectToPojo(req.getData(), MsChangeHistoryQuery.class);
//            List<MsInfoDto> msInfoDtoListChangeBefore = msChangeHistoryQuery.getMsInfoDtoListChangeBefore();
//            List<MsInfoDto> getMsInfoDtoListChangeAfter = msChangeHistoryQuery.getGetMsInfoDtoListChangeAfter();
//            String changeId = msChangeHistoryQuery.getChangeId();
//            ArrayList<MsChangeHistoryBean> arrayList = new ArrayList<>();
//            for (MsInfoDto msInfoDtoBefore : msInfoDtoListChangeBefore) {
//                //水表编号
//                String meterNoBefore = msInfoDtoBefore.getMeterNo();
//                //水表表身号
//                String factoryNoBefore = msInfoDtoBefore.getFactoryNo();
//                //水表型号
//                String meterModelNameBefore = msInfoDtoBefore.getMeterModelName();
//                //水表口径
//                String meterBoreNameBefore = msInfoDtoBefore.getMeterBoreName();
//                //水表厂家
//                String meterFactoryNameBefore = msInfoDtoBefore.getMeterFactoryName();
//                //水表分类
//                String meterTypeNameBefore = msInfoDtoBefore.getMeterTypeName();
//                //是否阀控
//                String valveControlNameBefore = msInfoDtoBefore.getValveControlName();
//                //是否远传
//                String transmissionNameBefore = msInfoDtoBefore.getTransmissionName();
//                //下行规约
//                String protocolNameBefore = msInfoDtoBefore.getProtocolName();
//                //水表型式
//                String meterPatternNameBefore = msInfoDtoBefore.getMeterPatternName();
//                //水表传感器
//                String meterSensorNameBefore = msInfoDtoBefore.getMeterSensorName();
//                //满值
//                double maxValueBefore = msInfoDtoBefore.getMaxValue();
//                //使用期限
//                int shelfLifeBefore = msInfoDtoBefore.getShelfLife();
//                //新旧表
//                String meterFormNameBefore = msInfoDtoBefore.getMeterFormName();
//                //合格证号
//                String meterCertBefore = msInfoDtoBefore.getMeterCert();
//                //水表状态
//                String meterStatusNameBefore = msInfoDtoBefore.getMeterStatusName();
//                //所属部门
//                String departBelongNameBefore = msInfoDtoBefore.getDepartBelongName();
//                for (MsInfoDto msInfoDtoAfter : getMsInfoDtoListChangeAfter) {
//                    String meterNoAfter = msInfoDtoAfter.getMeterNo();
//                    String factoryNoAfter = msInfoDtoAfter.getFactoryNo();
//                    String meterModelNameAfter = msInfoDtoAfter.getMeterModelName();
//                    String meterBoreNameAfter = msInfoDtoAfter.getMeterBoreName();
//                    String meterFactoryNameAfter = msInfoDtoAfter.getMeterFactoryName();
//                    String meterTypeNameAfter = msInfoDtoAfter.getMeterTypeName();
//                    String valveControlNameAfter = msInfoDtoAfter.getValveControlName();
//                    String transmissionNameAfter = msInfoDtoAfter.getTransmissionName();
//                    String protocolNameAfter = msInfoDtoAfter.getProtocolName();
//                    String meterPatternNameAfter = msInfoDtoAfter.getMeterPatternName();
//                    String meterSensorNameAfter = msInfoDtoAfter.getMeterSensorName();
//                    double maxValueAfter = msInfoDtoAfter.getMaxValue();
//                    int shelfLifeAfter = msInfoDtoAfter.getShelfLife();
//                    String meterFormNameAfter = msInfoDtoAfter.getMeterFormName();
//                    String meterCertAfter = msInfoDtoAfter.getMeterCert();
//                    String meterStatusNameAfter = msInfoDtoAfter.getMeterStatusName();
//                    String departBelongNameAfter = msInfoDtoAfter.getDepartBelongName();
//                    if (meterNoAfter.equals(meterNoBefore)){
//                        if (!factoryNoBefore.equals(factoryNoAfter)) {
//                            saveMsChangeHistory(factoryNoBefore,factoryNoAfter,arrayList,"水表表身号",userInfo);
//                        }if (!meterModelNameBefore.equals(meterModelNameAfter)){
//
//                            saveMsChangeHistory(meterModelNameBefore,meterModelNameAfter,arrayList,"水表型号",userInfo);
//                        }if (!meterBoreNameBefore.equals(meterBoreNameAfter)){
//
//                            saveMsChangeHistory(meterBoreNameBefore,meterBoreNameAfter,arrayList,"水表口径",userInfo);
//                        }if (!meterFactoryNameBefore.equals(meterFactoryNameAfter)){
//
//                            saveMsChangeHistory(meterFactoryNameBefore,meterFactoryNameAfter,arrayList,"水表厂家",userInfo);
//                        }if (!meterTypeNameBefore.equals(meterTypeNameAfter)){
//
//                            saveMsChangeHistory(meterTypeNameBefore,meterTypeNameAfter,arrayList,"水表分类",userInfo);
//                        }
//                        if (!valveControlNameBefore.equals(valveControlNameAfter)){
//
//                            saveMsChangeHistory(valveControlNameBefore,valveControlNameAfter,arrayList,"是否阀控",userInfo);
//                        }
//                        if (!transmissionNameBefore.equals(transmissionNameAfter)){
//                            saveMsChangeHistory(transmissionNameBefore,transmissionNameAfter,arrayList,"是否远传",userInfo);
//                        }
//                        if (!protocolNameBefore.equals(protocolNameAfter)){
//                            saveMsChangeHistory(protocolNameBefore,protocolNameAfter,arrayList,"下行规约",userInfo);
//                        }
//                        if (!meterPatternNameBefore.equals(meterPatternNameAfter)){
//                            saveMsChangeHistory(meterPatternNameBefore,meterPatternNameAfter,arrayList,"水表型式",userInfo);
//                        }
//                        if (!meterSensorNameBefore.equals(meterSensorNameAfter)){
//                            saveMsChangeHistory(meterSensorNameBefore,meterSensorNameAfter,arrayList,"水表传感器",userInfo);
//                        }
//                        if (maxValueBefore!=maxValueAfter){
//                            saveMsChangeHistory(String.valueOf(maxValueBefore),String.valueOf(maxValueAfter),arrayList,"满值",userInfo);
//                        }
//
//                        if (shelfLifeBefore!=shelfLifeAfter){
//                            saveMsChangeHistory(String.valueOf(shelfLifeBefore),String.valueOf(shelfLifeAfter),arrayList,"使用期限",userInfo);
//                        }
//                        if (!meterFormNameBefore.equals(meterFormNameAfter)){
//                            saveMsChangeHistory(meterFormNameBefore,meterFormNameAfter,arrayList,"新旧表",userInfo);
//                        }
//                        if (!meterCertBefore.equals(meterCertAfter)){
//                            saveMsChangeHistory(meterCertBefore,meterCertAfter,arrayList,"合格证号",userInfo);
//
//                        }
//                        if (!meterStatusNameBefore.equals(meterStatusNameAfter)){
//                            saveMsChangeHistory(meterStatusNameBefore,meterStatusNameAfter,arrayList,"水表状态",userInfo);
//
//                        }
//                        if (!departBelongNameBefore.equals(departBelongNameAfter)){
//                            saveMsChangeHistory(departBelongNameBefore,departBelongNameAfter,arrayList,"所属部门",userInfo);
//                        }
//
//                        break;
//                    }
//                }
//            }
//            if (CollectionUtils.isNotEmpty(arrayList)){
//                arrayList.forEach(dto->{
//                    dto.setChangeId(changeId);
//                });
//                Integer num = mapper.batchInsert(arrayList);
//                info.setData(num);
//                return info;
//            }
//            return info;
//
//
//        } catch (Exception e) {
//            info.setCode(Constant.MESSAGE_INT_FAIL);
//            info.setDescription("变更历史添加失败");
//            logger.error(e.getMessage(), e);
//        }
//        return info;
//    }
//
//    public void saveMsChangeHistory(String changeBefore,String changeAfter,List<MsChangeHistoryBean> arrayList,String changeItem,UserInfoBean userInfo){
//        MsChangeHistoryBean msChangeHistoryBean = new MsChangeHistoryBean();
//        msChangeHistoryBean.setChangeItem(changeItem);
//        msChangeHistoryBean.setOldItemValue(changeBefore);
//        msChangeHistoryBean.setNewItemValue(changeAfter);
//        msChangeHistoryBean.setCreateInfo(userInfo);
//        arrayList.add(msChangeHistoryBean);
//    }
//}
